package org.yohailong.javabase.dynamiclambda;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.Date;

/**
 * @author 朱海龙
 * 2025/6/3 15:43
 */
public class DynamicRun {


    public static void main(String[] args) {

        try {
            MethodHandles.Lookup lookup = MethodHandles.lookup();

            MethodType methodType = MethodType.methodType(Date.class);

            MethodHandle methodHandle = lookup.findSpecial(DynamicTime.class, "getDynamicTime", methodType, DynamicTime.class);

            final MethodHandle oldHandle = methodHandle;

            methodHandle = methodHandle.bindTo(new DynamicTime());

            final MethodHandle newHandle = methodHandle;
            System.out.println(oldHandle.equals(newHandle));
            Date date = (Date) methodHandle.invokeExact();

            System.out.println(date);


        } catch (Throwable e) {
            e.printStackTrace();
        }

    }


}
